/*
 * @Date: 2025-02-05 10:21:53
 * @LastEditors: 吴世扬 18368095041@163.com
 * @LastEditTime: 2025-02-24 15:16:36
 * @FilePath: /vue3-admin/src/api/user.ts
 */

import { request } from '@/utils';
import type { UserListItem, UserDetail } from '@/typings/api/user';

export class UserListParam implements PageParam<keyof UserListItem> {
    current = 1;
    size = 10;
    valid?: boolean;
    roleId?: number;
    departmentId?: number;
    username?: string;
}

export const readUserList = (data: UserListParam) => {
    return request<HttpResult<PageResult<UserListItem>>>({
        url: '/admin/api/v1/user/readList',
        method: 'post',
        data
    }).then((res) => {
        return res.data;
    });
};

export const readUserDetail = (id: number) => {
    return request<HttpResult<UserDetail>>({
        url: `/admin/api/v1/user/readDetail/${id}`,
        method: 'get'
    }).then((res) => {
        return res.data;
    });
};

export class UserParam {
    id?: number;
    username = '';
    valid = true;
    roleIds: number[] = [];
    deptIds: number[] = [];
    avatarId?: number;
    remark = '';
    gender = 0;
    mobile?: string;
}

export const createOrUpdateItem = (data: UserParam) => {
    return request<HttpResult>({
        url: '/admin/api/v1/user/save',
        method: 'post',
        data
    }).then((res) => {
        return res.data;
    });
};
